package main
import (
	"fmt"
	"time"
)

func hello() {
	fmt.Println("hello world goroutine")
}
func hello1(done chan bool) {
	fmt.Println("\nhello11111 world goroutine11111")
	time.Sleep(4 * time.Second)
	fmt.Println("hello11111 world goroutine2222222222")
	done <- true
}

// 22. 信道（channel）
func main(){

	// 信道的声明
	var a chan int
	if a == nil {
		fmt.Println("channel a is nil, going to define it")
		a = make(chan int)
		fmt.Printf("Type of a is %T", a)
	}

	// 信道的代码示例 //Go 协程。
	go  hello()
	time.Sleep(1 * time.Second)
	fmt.Println("mian function111")

	done := make(chan bool)
	fmt.Println("Main going to call hello go goroutine")
	go hello1(done) 
	<- done
	fmt.Println("mian function222")


}
